import moment from 'moment/moment';

const tableOption = {
  border: true,
  addBtn: false,
  viewBtn: false,
  editBtn: false,
  delBtn: false,
  index: true,
  menu: false,
  columnBtn: false,
  refreshBtn: false,
  indexLabel: '序号',
  column: [
    {
      label: '日期',
      prop: 'dayDate'
    },
    {
      label: '产品编码',
      prop: 'partNo'
    },
    {
      label: '产品名称',
      prop: 'partName'
    },
    {
      label: '批号',
      prop: 'lotNo',
      span: 7
    },
    {
      label: '客户编码',
      prop: 'partnerCode'
    },
    {
      label: '客户名称',
      prop: 'partnerName'
    },
    {
      label: '产量',
      prop: 'yield'
    },
    {
      label: '直通率',
      prop: 'firstPassYield'
    }
  ]
};

const option = {
  menuPosition: 'right',
  submitBtn: false,
  emptyBtn: false,
  column: [
    {
      label: '时间范围',
      span: 6,
      prop: 'examineDate',
      type: 'daterange',
      format: 'yyyy-MM-dd',
      valueFormat: 'yyyy-MM-dd',
      startPlaceholder: '开始日期',
      endPlaceholder: '结束日期',
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now() || moment(time).format('yyyy-MM-DD') === moment(new Date()).format('yyyy-MM-DD');
        }
      },
      rules: [
        {
          required: true,
          message: '请选择时间范围',
          trigger: 'blur'
        },
        {
          trigger: 'change',
          validator: (rule, value, callback) => {
            const endTime = value[1];
            const startTime = value[0];
            if (moment(endTime).diff(moment(startTime), 'day') > 6) {
              callback(new Error('查询时间最多选择7天的且时间'));
            }
            callback();
          }
        }
      ]
    },
    {
      label: '产品编码',
      prop: 'partNo',
      span: 6,
      rules: [
        {
          required: true,
          message: '请输入产品编码',
          trigger: 'blur'
        }
      ]
    },
    {
      label: '',
      prop: 'btn',
      span: 10,
      formslot: true
    }
  ]
};

export { tableOption, option };
